<template>
  <div class="detail">
    <div class="detailbox" v-html="list.content"></div>
    <van-goods-action>
      <van-goods-action-icon
        icon="home-o"
        text="首页"
        @click="onClickIcon('Home')"
      />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        @click="onClickIcon('Cart')"
      />
      <van-goods-action-icon
        icon="shop-o"
        text="热卖"
        @click="onClickIcon('List')"
      />
      <van-goods-action-button type="danger" text="加入购物车" @click="buyIt" />
    </van-goods-action>
  </div>
</template>

<script>
import { Toast } from "vant";
import { loadDetail } from "../services/goods.js";
import { addCart } from "../services/cart.js";
export default {
  methods: {
    onClickIcon(name) {
      this.$router.push({
        name,
      });
    },
    buyIt() {
      addCart(this.$route.query.id, 1).then((res) => {
        if (res.code === 1) {
          // 事件总线 加购成功后重新派发更新购物车数量事件
          this.$eventBus.$emit("updataCartCount");
          Toast(res.msg);
        } else Toast(res.msg);
      });
    },
  },

  data() {
    return {
      list: {},
    };
  },
  created() {
    loadDetail(this.$route.query.id).then(
      (res) => (this.list = { ...res.data })
    );
  },
};
</script>

<style lang="scss" scoped>
</style>